package com.example.dilidili_ting.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.dilidili_ting.R;
import com.example.dilidili_ting.utils.SharedPreferencesUtilsTing;
import com.thecode.aestheticdialogs.AestheticDialog;
import com.thecode.aestheticdialogs.DialogStyle;
import com.thecode.aestheticdialogs.DialogType;

import java.util.Timer;
import java.util.TimerTask;

public class SettingActivityTing extends AppCompatActivity {

    private LinearLayout xgmmTing;
    private LinearLayout szmbTing;
    private LinearLayout tcdlTing;
    private RelativeLayout llBarTing;
    private ImageView ivBackTing;
    private TextView tvTitleTing;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_ting);
        initView();
    }

//    初始化控件
    private void initView() {
        llBarTing = (RelativeLayout) findViewById(R.id.ll_bar_ting);
        ivBackTing = (ImageView) findViewById(R.id.iv_back_ting);
        tvTitleTing = (TextView) findViewById(R.id.tv_title_ting);
        xgmmTing = (LinearLayout) findViewById(R.id.xgmm_ting);
        szmbTing = (LinearLayout) findViewById(R.id.szmb_ting);
        tcdlTing = (LinearLayout) findViewById(R.id.tcdl_ting);
        tvTitleTing.setText("");
        ivBackTing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SettingActivityTing.this.finish();//关闭设置页面
            }
        });
        //修改密码的点击事件
        xgmmTing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO:跳转到密码修改页面
                Intent intent=new Intent(SettingActivityTing.this, ChangePasswordTing.class);
                startActivity(intent);      //从设置页面打开修改密码页面
            }
        });
        //设置密保的点击事件
        szmbTing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO:跳转到设置密保页面
                Intent intent=new Intent(SettingActivityTing.this, SetSecurityActivityTing.class);
                startActivity(intent);//打开设置密保页面
            }
        });
        //退出登录的点击事件
        tcdlTing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AestheticDialog.Builder(SettingActivityTing.this, DialogStyle.EMOTION, DialogType.SUCCESS)
                        .setTitle("SUCCESS")
                        .setMessage("退出登录成功")
                        .setDuration(2000)
                        .show();
                //清除登录状态和登录时的用户名
                SharedPreferencesUtilsTing.clearLoginStatus(SettingActivityTing.this);
                //退出登录成功后把退出成功的状态传递到MainActivity中
                Timer timer=new Timer();
                TimerTask task=new TimerTask() {
                    @Override
                    public void run() {
                        Intent data=new Intent();
                        data.putExtra("isLogin",false);
                        setResult(RESULT_OK,data);
                        SettingActivityTing.this.finish();
                    }
                };
                timer.schedule(task,2000);
            }
        });
    }
}